package ar.uba.fi.taller2.ftrs.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.filechooser.FileFilter;

import ar.uba.fi.taller2.ftrs.repo.RepositoryManager;
@SuppressWarnings("serial")
public class DialogoCrear extends JDialog {
		
		private JTextField jTextFieldPath;
		private JButton buttonOk;
		private JButton buttonCancel;
		
		private Action accionAceptar;
		private Action accionCancelar;
				
		private JPanel jPanelNewPrincipal;
		private JPanel jPanelNewBotonera;
		
		private JFrame frmPadre;
		
		public DialogoCrear(JFrame framePadre)
		{
			super(framePadre, "Agregar Documento", true);
			
			
			frmPadre=framePadre;
			
			setLayout(new GridBagLayout());
			
			
			jTextFieldPath= new JTextField(40);
			
			//Boton Aceptar
			accionAceptar = new AbstractAction("Aceptar") {
				{
					putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
					putValue(AbstractAction.SHORT_DESCRIPTION, "Aceptar");
				}
				public void actionPerformed(ActionEvent e)
				{
				try {						
						DialogoCrear.this.setVisible(false);
						((Ventana)frmPadre).getRepositorios().createRepository(jTextFieldPath.getText());						
					} catch (Exception e1) {
						e1.printStackTrace();
					}
				}
			};
			buttonOk= new JButton(accionAceptar);
			
			//Boton Cancelar
			accionCancelar = new AbstractAction("Cancelar") {
				{
					putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
					putValue(AbstractAction.SHORT_DESCRIPTION, "Cancelar");
				}
				public void actionPerformed(ActionEvent e)
				{
					setVisible(false);
				}
			};
			buttonCancel= new JButton(accionCancelar);
			jPanelNewPrincipal= new JPanel();
			jPanelNewBotonera= new JPanel();
			
			jPanelNewPrincipal.setLayout(new GridBagLayout());
			jPanelNewBotonera.setLayout(new GridBagLayout());
			
			//Se llena el jPanelNewPrincipal
			GridBagConstraints c = new GridBagConstraints();
			c.fill=GridBagConstraints.BOTH;
			int y = 0;
			c.weightx = 0;
			c.insets = new Insets(3, 6, 3, 6);
			jPanelNewPrincipal.add(new JLabel("Repositorio:"), c);
			
			c.gridy = ++y;
			
			c.weightx = 0;
			jPanelNewPrincipal.add(new JLabel("Nombre:"), c);
			
			c.weightx = 1;
			jPanelNewPrincipal.add(jTextFieldPath, c);
				
			c.gridy = ++y;
			
			c.weightx = 0;
			//	jPanelNewPrincipal.add(jCheckBoxUrlPath , c);
					
			//Se llena el jPanelNewBotonera
			c = new GridBagConstraints();
			c.fill=GridBagConstraints.BOTH;
			c.insets = new Insets(3, 3, 3, 3);
			jPanelNewBotonera.add(buttonOk, c);
			c.insets = new Insets(3, 3, 3, 3);
			jPanelNewBotonera.add(buttonCancel, c);
			
			//Se llena el dialogoNew
			c = new GridBagConstraints();
			c.fill=GridBagConstraints.BOTH;
			c.weightx = 1;
			c.weighty = 1;
			add(jPanelNewPrincipal, c);
			
			c.gridy = 1;
			c.weightx = 1;
			c.weighty = 0;
			c.fill=GridBagConstraints.NONE;
			c.anchor = GridBagConstraints.EAST;
			add(jPanelNewBotonera, c);
			
			JRootPane rootPane = getRootPane();
			rootPane.setDefaultButton(buttonOk);
			rootPane.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "salimo");
			rootPane.getActionMap().put("salimo", new AbstractAction() {
				public void actionPerformed(ActionEvent e)
				{
					setVisible(false);
				}
			});
			pack();
			setLocationRelativeTo(framePadre);
		}
		
	}
	
